import { KingChampionShipResultTabBase } from "./KingChampionShipResultTabBase";
import { ObjCreate } from "../../../common/ObjCreate";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { Language } from "../../../../../../extend/language/Language";
import { PageSelecter } from "../../../common/pageSelect/PageSelecter";
import { GBoxDirection } from "../../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { KingChampionShipResultTabRender2 } from "../render/KingChampionShipResultTabRender2";
import { SRobCityTwoRanks } from "../../../../../../Message/Public/SRobCityTwoRanks";
import { DataProvider } from "../../../../../../fl/data/DataProvider";
import { GRCTwoRankData } from "../../guildRobCityCopy/copyTwo/GRCTwoRankData";
import { Cache } from "../../../../cache/Cache";
import { KingChampionShipUtil } from "../KingChampionShipUtil";
import { GameProxy } from "../../../../mvc/GameProxy";
import { GTileList } from "../../../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../../../com/mui/controls/GButton";
type int = number;
//class KingChampionShipResultTab2
    
    export  class KingChampionShipResultTab2 extends KingChampionShipResultTabBase
    {
        constructor()
        {
            super();
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            ObjCreate.createBg(5, 0, 410, 1, this, ImagesConst.SplitLine);
            var loc1=Language.getString(80409);
            var loc2=loc1.split(",");
            this.createCategory(loc2, 40);
            ObjCreate.createBg(5, 34, 410, 1, this, ImagesConst.SplitLine);
            this._pageSelecter = ObjCreate.createPageSelecter(154, 384, this, PageSelecter.CompleteMode);
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.pageChangeHandler);
            this._list = ObjCreate.createTileList(0, 34, 420, 350, this);
            this._list.direction = GBoxDirection.VERTICAL;
            this._list.rowHeight = 34;
            this._list.columnWidth = 330;
            this._list.setSize(420, 350);
            this._list.setStyle("cellRenderer", KingChampionShipResultTabRender2);
            this._myRankBtn = ObjCreate.createGButton(Language.getString(60985), 74, 382, 75, 26, this);
            this._myRankBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onMyRankBtnClick);
            return;
        }

        public setDatas(arg1: SRobCityTwoRanks): void
        {
            if (arg1 == null) 
            {
                return;
            }
            this._list.dataProvider = new DataProvider(this.getKillRankData(arg1));
            this._pageSelecter.maxPage = arg1.totalPage;
            this._pageSelecter.currentPage = arg1.targetPage;
            this._list.drawNow();
            return;
        }

        /* internal  */getKillRankData(arg1: SRobCityTwoRanks): Array<any>
        {
            var loc2=0;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=null;
            var loc1=[];
            loc2 = 0;
            while (loc2 < arg1.robCityTwoPlayers.length) 
            {
                (loc3 = new GRCTwoRankData(arg1.robCityTwoPlayers[loc2])).rank = (arg1.targetPage - 1) * 10 + (loc2 + 1);
                loc3.guildName = Cache.instance.kingChampionShip.getGuildName(loc3.force);
                loc4 = KingChampionShipUtil.getKillScroe(loc3.killNum);
                loc5 = Cache.instance.kingChampionShip.getGuildScore(loc3.force);
                loc5 = KingChampionShipUtil.getGuildScore(loc5);
                loc6 = {"rank": loc3.rank, "name": loc3.name, "killScore": loc4, "guildScore": loc5, "totalScore": loc4 + loc5};
                loc1.push(loc6);
                ++loc2;
            }
            loc1.sort(this.sortKillRankRes);
            return loc1;
        }

        /* internal  */sortKillRankRes(arg1: Object, arg2: Object): int
        {
            if (int(arg1["rank"]) <= int(arg2["rank"])) 
            {
                return -1;
            }
            return 1;
        }

        /* internal  */onMyRankBtnClick(arg1): void
        {
            this.getRankData(true);
            return;
        }

        /* internal  */pageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.getRankData();
            return;
        }

        public getRankData(arg1: Boolean=false): void
        {
            var loc1=flash.utils.getTimer();
            if (loc1 - this.lastClickTime > 1000) 
            {
                this.lastClickTime = loc1;
                GameProxy.robCityProxy.getKingChampionShipRank(1, 10, this._pageSelecter.currentPage, arg1);
            }
            return;
        }

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_myRankBtn: GButton;

        /* internal */ /* var */lastClickTime: int=0;
    }
